<?php


/** Zend_Controller_Action */
require_once 'Zend/Controller/Action.php';
require_once 'Zend/Log.php';
require_once 'Zend/Log/Writer/Stream.php';

class ErrorController extends Zend_Controller_Action {
	public function errorAction() {
		$errors = $this->_getParam('error_handler');

		switch ($errors->type) {
			case Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_CONTROLLER :
			case Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_ACTION :
				// 404 error -- controller or action not found
				$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');

				$content =<<<EOH
<h1>Error!</h1>
<p>The page you requested was not found.</p>
EOH;
				break;
			default :
				// application error
				$content =<<<EOH
<h1>Error!</h1>
<p>An unexpected error occurred with your request. Please try again later.</p>
EOH;
				$content .= " ({$exception})";
				$exception = $errors->exception;
				$log = new Zend_Log(new Zend_Log_Writer_Stream('applicationException.log'));
				$log->debug($exception->getMessage() . "\n" . $exception->getTraceAsString());
				break;
		}

		// Clear previous content
		$this->getResponse()->clearBody();
		$registry = Zend_Registry :: getInstance();
		$registry->smarty->assign('errorContent', $content);
		$registry->smarty->display('default_error_error.tpl');
	}

}
?>